<?php

/**
 * winbinder 패키지 
 * 
 * 
 * @package php.ui.winbinder
 */

/**
 * 단축키 설정 클래스 
 *
 * <code>
 * // 1. accel 지정 
 * new WBAccel(array(
 *     'parent' => $window,
 *     'items' => array(
 *          array('key' => 'F1', 'callback' => 'click_func'),
 *          new WBAccelTemplate(array('key' => 'F2', 'callback' => 'click_func_2'))
 *     )
 * )); 
 * 
 * // 2. 컨트롤 단축키 지정 
 * new WBPushButton(array(
 *    'parent' => $window,
 *    'caption' => 'accel button', 
 *    'accel' => 'F1',
 * ));
 * 
 * // 3. window 에서 runAccel() 실행 
 * $window->runAccel();
 * </code>
 *
 * @package php.ui.winbinder
 */
class WBAccel extends WBControl { 
	public function __construct($options = array()) { 
		$options['class'] = Accel;

		parent::__construct($options);
	}

	protected function initCreate() { 
		if ($this->getOption('items')) { 
			$temp = array();

			foreach ($this->getOption('items') as $item) { 

				if (is_array($item)) { 
					if ($item['id']) { 
						$temp[] = array($item['id'], $item['key']);
					} else { 
						$accelItem = new WBAccelItem(array(
							'key' => $item['key'],
							'callback' => $item['callback'],
						));

						$temp[] = $accelItem->getAccelTemplate();
					} 
				} else if ($item instanceof WBAccelItem) { 
					$temp[] = $item->getAccelTemplate();
				}
			}

			$this->setOption('caption', $temp);
		}
	}


}

?>